<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>迭代器对象</title>
    <script>
      // 制作一个可迭代的对象
      class Player {
        constructor(list) {
          this.list = list;
        }
        [Symbol.iterator]() {
          let current = 0; //相ne当于索引
          let that = this;
          return {
            next() {
              return current < that.list.length
                ? { value: that.list[current++], done: false }
                : { done: true };
            },
          };
        }
      }
      let player = new Player(["Curry", "Harden", "LeBron"]);
      for (let tmp of player) {
        console.log(tmp);
        /*
         * Curry
         * Harden
         * LeBron
         */
      }
    </script>
  </head>
  <body></body>
</html>
